<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/picker.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/beautify-time.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">

    <link rel="stylesheet" href="${newframe}/css/base/IE8.css" type="text/css"/>

    <style>
        .select2-container {
            width: 100% !important;
        }
        .btn-myStyle{
            background-color: #2c3e50;
            color:#fff;
        }
    </style>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${frames}/laydate/laydate.dev.js"></script>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <script src="${newframe}/js/select2.js"></script>

    <script>
        $(document).ready(function () {
            initKind("hospId");
            <c:if test="${hl_hospital!=null}">
            $("#select2-hospId-container").text("${hl_hospital.hospName}");
            </c:if>
            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    username: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    status: {
                        validators: {
                            notEmpty: true
                        }
                    }
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();

                var _url = "";
                if ($("#id").val() == null || $("#id").val() == '') {
                    _url = '${URL_HOSPTIALCONVERSION_ADD}';
                } else {
                    _url = '${URL_HOSPTIALCONVERSION_UPDATE}';
                }

                $.ajax({
                    url: _url,
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    dataType : 'json',
                    error: function (data) {
                        alert('error');
                    },
                    success: function (data) {
                        if(!data.success){
                            alert(data.msg);
                        }else{
                            closeFrame();
                        }
                    }
                });

            });
        });
        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }
        function initKind(id){
            $("#"+id).select2({
                placeholder: '请选择医院',
                ajax: {
                    url: '${URL_HL_HOSPITAL_SELECT}',
                    dataType: 'json',
                    type: "post",
                    delay: 250,
                    data: function (params) {
                        var data=new Object();
                        data["iDisplayLength"]=10;
                        if(params.page==undefined){
                            data["iDisplayStart"]=0;
                        }else {
                            data["iDisplayStart"]= (params.page-1)*10;
                        }
                        if(params.term!=undefined){
                            data["hospName"]= params.term;
                        }
                        return data;
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.data,
                            pagination: {
                                more: (params.page * 10) < data.msg
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 0,
                templateResult: formatRepo, // omitted for brevity, see the source of this page
                templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
            });
        }
        function formatRepo(repo) {
            if (repo.loading) return repo.text;
            var markup = "<div class='select2-result-repository clearfix'>" +
                "<div class='select2-result-repository__title'>" + repo.hospName + "</div></div>";
            return markup;
        }
        function formatRepoSelection(repo) {
            console.log(repo.hospName);
            return repo.hospName;
        }
    </script>
</head>
<body style="width: 98%">
<form id="myForm" class="form-horizontal" method="post">
    <input type="hidden" id="id" name="id" value="${entity.id}"/>
    <input type="hidden" name="createTime" value="${entity.createTime}"/>
    <input type="hidden" name="updateTime" value="${entity.updateTime}"/>
    <div class="clearfix">
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">医卫士医院名</label>
            <div class="col-sm-8">
                <select id="hospId" name="myHospId" class="form-control">
                    <c:if test="${hl_hospital!=null}">
                        <option value="${hl_hospital.id}">${hl_hospital.hospName}</option>
                    </c:if>
                </select>
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">接入医院编码</label>
            <div class="col-sm-8">
                <input type="text" id="hospitalCode" name="hospitalCode" class="form-control" value="${entity.hospitalCode}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">登陆地址url</label>
            <div class="col-sm-8">
                <input type="text" id="loginUrl" name="loginUrl" class="form-control" value="${entity.loginUrl}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">查询检测报告大项url地址</label>
            <div class="col-sm-8">
                <input type="text" id="queryReportKindUrl" name="queryReportKindUrl" class="form-control" value="${entity.queryReportKindUrl}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">查询检测报告明细url地址</label>
            <div class="col-sm-8">
                <input type="text" id="queryReportDetailUrl" name="queryReportDetailUrl" class="form-control" value="${entity.queryReportDetailUrl}">
            </div>
        </div>
    </div>

    <div class="modal-footer" style="text-align: center ">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModalButt"
                onclick="closeFrame()">关闭
        </button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>
</body>
</html>